package com.koocloud.electroplatemanage.utils;

import java.io.*;
import java.util.Properties;

public class ConfigurarionUtil {
    public static String getConfigData(String str) throws IOException {
        String returnStr = "";
        InputStream in =null;
        try {
            //加载配置文件
            Properties properties = new Properties();
            in = new BufferedInputStream (new FileInputStream("config/configData.properties"));
            properties.load(in);
            returnStr = properties.getProperty(str);
        } catch (Exception e) {
            in.close();
            e.printStackTrace();
        } finally {
            in.close();
        }
        return returnStr;
    }
    public static void setConfigData(String key,String value) throws IOException {

        FileOutputStream file = null;
        InputStream in =null;
        try {

            //加载配置文件
            Properties properties = new Properties();
            in = new BufferedInputStream (new FileInputStream("config/configData.properties"));
            properties.load(in);
            //重新写入配置文件
            file = new FileOutputStream("config/configData.properties");
            properties.put(key, value);
            properties.store(file,null); //这句话表示重新写入配置文件
        } catch (Exception e) {
            file.close();
            e.printStackTrace();
        } finally {
            file.close();
        }


    }
}

